<?php
include_once('../_inc/config.php');
include_once('../_class/db.php');
function check_date($date)
{
 if (date("Y-m-d") >= $date)
  return 1;
 else
  return 0;
}

 $sql = new db();
 $req = "SELECT c.* FROM commande AS c WHERE c.Id_Commande='".$_GET['id']."'";
 $sql->query($req);
 $data = $sql->fetch_array();
 Header("content-type: application/xml");
 $req = "SELECT * FROM preparation WHERE Id_Commande='".$_GET['id']."'";
 $sql->query($req);
 if ($sql->num_rows() > 0)
  $prepa = $sql->fetch_array();
?>
 <data>
<?php
 $dateD = date("r", strtotime($data['Date_Commande']));
 $dateF = date("r", strtotime($data['Date_fin_Liv']));
 echo "<event start='".$dateD."' title='' caption='Debut de la commande' ";
 $print = (check_date($data['Date_Commande']) == 1) ? "icon='".ABS_PATH."_gfx/icons/accept.png'>" : "icon='".ABS_PATH."_gfx/icons/cross.png'>";
 echo $print."Debut de la commande</event>";
 echo "<event start='".$dateF."' title='' caption='Fin de la commande' ";
 $print = (check_date($data['Date_fin_Liv']) == 1) ? "icon='".ABS_PATH."_gfx/icons/accept.png'>" : "icon='".ABS_PATH."_gfx/icons/cross.png'>";
 echo $print."Fin de la commande</event>";
 echo "<event start='".$dateD."' end='".$dateF."' durationEvent='true' color='#CC0033' caption='Commande' title=''>Cout : ".$data['Montant']." euro</event>";
 if (isset($prepa))
 {
  $dateP = date("r", strtotime($prepa['Date_diffusion_ordre_prepa']));
  $datePF = date("r", strtotime($prepa['Date_fin']));
  echo "<event start='".$dateP."' title='' caption='Debut entrepot' ";
  $print = (check_date($prepa['Date_diffusion_ordre_prepa']) == 1) ? "icon='".ABS_PATH."_gfx/icons/accept.png'>" : "icon='".ABS_PATH."_gfx/icons/cross.png'>";
  echo $print."Debut de la preparation</event>";
  echo "<event start='".$datePF."' title='' caption='Fin de la preparation' ";
  $print = (check_date($prepa['Date_fin']) == 1) ? "icon='".ABS_PATH."_gfx/icons/accept.png'>" : "icon='".ABS_PATH."_gfx/icons/cross.png'>";
  echo $print."Fin la preparation</event>";
  echo "<event start='".$dateP."' end='".$datePF."' durationEvent='true' caption='Entrepot' color='#3333CC' title=''>Entrepot</event>";
 }
?>
 </data>